package cn.kone.controller.manager;

import cn.kone.pojo.domain.PayOrder;
import cn.kone.pojo.query.PageQueryWrapper;
import cn.kone.result.JSONResult;
import cn.kone.result.PageResult;
import cn.kone.service.IPayOrderService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Tag(name = "", description = "")
@RestController
@RequestMapping("/manager/payOrder")
public class PayOrderController {

    @Autowired
    public IPayOrderService payOrderService;












    //微信支付接口
    @PostMapping("/prePay/{orderNo}")
    public JSONResult prePay(@PathVariable String orderNo) {
        return JSONResult.success(payOrderService.prePay(orderNo));


    }

    @Operation(summary = "保存PayOrder", description = "基础对象保存接口")
    @Parameter(name = "payOrder", description = "保存的对象", required = true)
    @PostMapping
    public JSONResult save(@RequestBody @Valid PayOrder payOrder) {
        return JSONResult.success(payOrderService.save(payOrder));
    }

    @Operation(summary = "修改PayOrder", description = "基础对象修改接口")
    @Parameter(name = "payOrder", description = "修改的对象", required = true)
    @PutMapping
    public JSONResult update(@RequestBody @Valid PayOrder payOrder) {
        return JSONResult.success(payOrderService.updateById(payOrder));
    }

    //删除对象
    @Operation(summary = "删除PayOrder", description = "基础对象删除接口，采用状态删除")
    @Parameter(name = "id", description = "删除的对象ID", required = true)
    @DeleteMapping(value = "/{id}")
    public JSONResult delete(@PathVariable("id") Long id) {
        return JSONResult.success(payOrderService.removeById(id));
    }

    //获取对象
    @Operation(summary = "获取PayOrder", description = "基础对象获取接口")
    @Parameter(name = "id", description = "查询的对象ID", required = true)
    @GetMapping(value = "/{id}")
    public JSONResult get(@PathVariable("id") Long id) {
        return JSONResult.success(payOrderService.getById(id));
    }

    //获取列表:PageQueryWrapper作为通用的查询对象
    @Operation(summary = "查询PayOrder列表", description = "基础对象列表查询，不带分页")
    @Parameter(name = "query", description = "查询条件", required = true)
    @PostMapping(value = "/list")
    public JSONResult list(@RequestBody PageQueryWrapper<PayOrder> query) {
        QueryWrapper<PayOrder> wrapper = new QueryWrapper<>();
        //实体类作为查询条件
        wrapper.setEntity(query.getQuery());
        return JSONResult.success(payOrderService.list(wrapper));
    }

    //分页查询
    @Operation(summary = "查询PayOrder分页列表", description = "基础对象列表查询，带分页")
    @Parameter(name = "query", description = "查询条件，需要指定分页条件", required = true)
    @PostMapping(value = "/pagelist")
    public JSONResult page(@RequestBody PageQueryWrapper<PayOrder> query) {
        //分页查询
        Page<PayOrder> page = new Page<PayOrder>(query.getPage(), query.getRows());
        QueryWrapper<PayOrder> wrapper = new QueryWrapper<>();
        //实体类作为查询条件
        wrapper.setEntity(query.getQuery());
        //分页查询
        page = payOrderService.page(page, wrapper);
        //返回结果
        return JSONResult.success(new PageResult<PayOrder>(page.getTotal(), page.getRecords()));
    }

}
